//
//  ArtGalleryCell_third.m
//  jingdongfang
//
//  Created by MTiMac01 on 2017/8/21.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "ArtGalleryCell_third.h"

@interface ArtGalleryCell_third ()
{
    UIImageView *imgView;
    UILabel *numberLaber;
    UILabel *treasureL;
}

@end
@implementation ArtGalleryCell_third

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self loadUI];
        self.isTreasure = NO;
        self.isGus = NO;
    }
    return self;
}
- (void)loadUI
{
//    self.contentView.clipsToBounds = YES;

    imgView = [[UIImageView alloc] initWithFrame:CGRectZero];
    imgView.contentMode = UIViewContentModeScaleAspectFill;
    imgView.clipsToBounds=YES;
    [self.contentView addSubview:imgView];
    
    numberLaber = [[UILabel alloc] init];
    numberLaber.textColor = [UIColor whiteColor];
    numberLaber.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"B-16-2"]];
    numberLaber.font = [UIFont systemFontOfSize:13];
    numberLaber.textAlignment = NSTextAlignmentLeft;
    [imgView addSubview:numberLaber];
//    numberLaber.hidden = YES;
    
    treasureL = [[UILabel alloc] init];
    treasureL.textColor = [UIColor whiteColor];
    treasureL.hidden = YES;
    treasureL.backgroundColor = [UIColor colorWithHex:@"#9b7625"];
    treasureL.font = [UIFont systemFontOfSize:10];
    treasureL.textAlignment = NSTextAlignmentCenter;
    [imgView addSubview:treasureL];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    imgView.image = nil;
    imgView.backgroundColor = [UIColor mainRandomColor];
    imgView.frame = CGRectMake(0, 0, self.width, self.height);
    
    numberLaber.frame = CGRectMake(0, self.height - 20, self.width, 20);
    numberLaber.text = _titleL;
    numberLaber.hidden = _isGus ? YES : NO;
    
    treasureL.frame = CGRectMake(self.width - 65, 0, 60, 19);
//    treasureL.text = @"镇馆之宝";
    treasureL.text = NSLocalizedString(@"Masterpiece", nil);
    treasureL.hidden = _isTreasure ? NO : YES;
    [imgView sd_setImageWithURL:[NSURL URLWithString:self.imgUrl] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        if (image) {
            // Image load from disk or download from network.
            if (cacheType == SDImageCacheTypeNone || cacheType == SDImageCacheTypeDisk) {
                imgView.alpha = 0.2;
                [UIView transitionWithView:imgView
                                  duration:2.0
                                   options:UIViewAnimationOptionCurveEaseInOut
                                animations:^{
                                    imgView.alpha = 1.0;
                                    [imgView setImage:image];
                                } completion:NULL];
            } else {
                imgView.alpha = 1.f;
            }
        }
    }];
}

- (void)awakeFromNib
{
    [super awakeFromNib];
}

@end
